
function Image(id, source) {
	var that = this;
	this.element = document.createElement("div");
	this.superClass = Element;
	this.superClass();
	this.type = "image";
	this.source;
	this.id = id;
	this.actions = new Object();
	this.setSource = function (source) {
		this.hide();
		if (source) {
			this.source = source;
			if (this.content) {
				this.element.removeChild(this.content);
			}
			this.content = document.createElement("img");
			this.content.src = source;
			this.content.onload = function () {
				that.show();
			};
			this.element.appendChild(this.content);
		}
	};
	this.element.id = id;
	this.element.style.position = "absolute";
	this.element.onmousedown = this.logic.onmousedown;
	this.element.ondblclick = actionListener;
	disableSelect(this.element);
	this.setSource(source);
	allElements[id] = this;
}
function Form(id, action, enctype, method) {
	this.type = "form";
	this.id = id;
	this.action = action;
	this.enctype = enctype;
	this.method = method;
	this.elements = new Object();
	this.setAction = function (action) {
		this.action = action;
		this.content.action = action;
	};
	this.setEncType = function (enctype) {
		this.enctype = enctype;
		this.content.enctype = enctype;
	};
	this.setMethod = function (method) {
		this.method = method;
		this.content.method = method;
	};
	this.submit = function () {
		this.content.submit();
	};
	this.element = document.createElement("form");
	this.content = this.element;
	this.element.id = id;
	this.setAction(action);
	this.setEncType(enctype);
	this.setMethod(method);
	allElements[id] = this;
}
Form.prototype = new Container;
function IFrame(id) {
	this.type = "iframe";
	var that = this;
	this.id = id;
	this.ready = false;
	this.element = document.createElement("iframe");
	this.element.style.borderWidth = 0;
	this.element.style.position = "absolute";
	this.element.style.overflow = "hidden";
	this.element.id = id;
	this.element.name = id;
	this.content = null;
	this.source = null;
	this.intervalId = null;
	this.elements = new Object();
	this.copyActionListeners = function (element) {
		oldElement = element.element;
		element.element = that.document.getElementById(element.id);
		if (oldElement != null && oldElement.onmousedown != null) {
			element.element.onmousedown = oldElement.onmousedown;
		}
		for (i in element.elements) {
			this.copyActionListeners(element.elements[i]);
		}
	};
	this.setContent = function () {
		that.document = window.frames[id].document;
		if (that.document != null) {
			that.content = that.document.getElementById("content");
			if (that.elements && that.content != null) {
				for (var i in that.elements) {
					if (that.elements[i].element.outerHTML) {
						var oldElement = that.elements[i];
						that.content.innerHTML += oldElement.element.outerHTML;
						that.copyActionListeners(that.elements[i]);
						parent.allElements[that.elements[i].id].element = that.elements[i].element;
					} else {
						that.content.appendChild(that.elements[i].element);
					}
				}
			}
			clearInterval(that.intervalId);
			this.ready = true;
		}
	};
	this.setContentIE = function () {
		if (that.element.readyState == "complete") {
			that.setContent();
		}
	};
	this.waitToBeReady = function () {
		this.intervalId = setInterval(function () {
			that.setContent();
		}, 100);
	};
	this.setSource = function (source) {
		this.source = source;
		this.element.src = source;
	};
	this.addElement = function (elementObject) {
		elementObject.parent = this;
		elementObject.element.style.position = "absolute";
		elementObject.element.style.left = elementObject.x;
		elementObject.element.style.top = elementObject.y;
		if (this.ready) {
			this.content.appendChild(elementObject.element);
		}
		this.elements[elementObject.id] = elementObject;
	};
	allElements[id] = this;
	this.element.onload = that.setContent;
	this.element.onreadystatechange = that.setContentIE;
}
IFrame.prototype = new Container;
function MenuItem(id, title, action) {
	var that = this;
	this.type = "menuItem";
	this.id = id;
	this.element = document.createElement("li");
	this.content = this.element;
	this.link = document.createElement("a");
	this.text = document.createTextNode("");
	this.title;
	this.action;
	this.actions = new Object();
	this.container;
	this.subMenu = null;
	this.setTitle = function (title) {
		var text = document.createTextNode(title);
		this.text.parentNode.replaceChild(text, this.text);
		this.text = text;
		this.title = title;
	};
	this.setSubMenu = function (subMenu) {
		this.subMenu = subMenu;
		this.subMenu.element.style.display = "none";
		this.element.appendChild(subMenu.element);
	};
	this.link.appendChild(this.text);
	this.setTitle(title);
	this.action = action;
	this.element.appendChild(this.link);
	function showSubMenu() {
		that.link.className = "menu_hover";
		var subMenu = this.childNodes[1];
		if (subMenu != null) {
			subMenu.style.display = "block";
			that.parent.container.style.zIndex = 999999;
		}
	}
	function hideSubMenu() {
		that.link.className = "menu";
		var subMenu = this.childNodes[1];
		if (subMenu != null) {
			subMenu.style.display = "none";
			that.parent.container.style.zIndex = 0;
		}
	}
	this.actionListener = function (e) {
		var element = allElements[this.id];
		if (element.action) {
			postAction(element.id, element.action);
		}
	};
	this.element.onmouseover = showSubMenu;
	this.element.onmouseout = hideSubMenu;
	this.element.onmousedown = this.actionListener;
	this.element.className = "menu";
	this.element.id = id;
	this.link.className = "menu";
	allElements[id] = this;
}
MenuItem.prototype = new Element;
function Menu(id) {
	this.type = "menu";
	this.elements = new Object();
	this.actions = new Object();
	this.element = document.createElement("ul");
	this.id = id;
	this.length = 0;
	this.items = new Object();
	this.addItem = function (item) {
		this.element.appendChild(item.content);
		this.items[length] = item;
		this.length = this.length + 1;
		item.parent = this;
	};
	this.clear = function () {
		this.items = new Object();
	};
	this.getItems = function () {
		return this.items;
	};
	this.element.className = "menu";
	disableSelect(this.element);
	allElements[id] = this;
}
Menu.prototype = new Container;
function SelectBox(id, name) {
	this.type = "selectbox";
	this.id = id;
	this.actions = new Object();
	this.options = new Array();
	this.selected = 0;
	this.element = document.createElement("div");
	this.content = document.createElement("select");
	this.content.id = id;
	this.element.appendChild(this.content);
	this.content.onchange = actionListener;
	if (name) {
		this.content.name = name;
	}
	this.element.style.position = "absolute";
	this.addOption = function (option){
		this.content.options[this.content.options.length] = new Option(option, option);
	};
	this.remOption = function (index){
		this.content.options[index]=null;
	};
	this.select = function (index){
		this.selected = index;
		this.content.options[index].selected = true;
	};
	allElements[id] = this;
}
SelectBox.prototype = new Element;
function Input(elementId, type, name) {
	this.type = "input";
	if (type) {
		this.inputType = type;
	} else {
		this.inputType = "text";
	}
	this.actions = new Object();
	function setValue(value) {
		if (this.inputType != "file") {
			this.value = value;
			this.enabledElement.value = value;
			var text = document.createTextNode(this.value);
			this.disabledElement.replaceChild(text, this.text);
			this.text = text;
		}
	}
	function appendValue(value) {
		this.value = this.value + value;
		this.setValue(this.value);
	}
	function disable() {
		this.disabled = true;
		this.enabledElement.style.visibility = "hidden";
		this.enabledElement.style.display = "none";
		this.disabledElement.style.visibility = "inherit";
		this.disabledElement.style.display = "block";
		this.content = this.disabledElement;
	}
	function enable() {
		this.disabled = false;
		this.disabledElement.style.visibility = "hidden";
		this.disabledElement.style.display = "none";
		this.enabledElement.style.visibility = "inherit";
		this.enabledElement.style.display = "block";
		this.enabledElement.focus();
		this.content = this.enabledElement;
	}
	if (name) {
		if (navigator.appName != "Microsoft Internet Explorer") {
			this.enabledElement = document.createElement("input");
			this.enabledElement.name = name;
		} else {
			this.enabledElement = document.createElement("<input onchange = 'actionListener;' name='" + name + "'>");
		}
	} else {
		this.enabledElement = document.createElement("input");
	}
	this.setWidth = function (width) {
		this.content.style.width = width;
		this.element.style.width = width;
		this.enabledElement.style.width = width;
		this.disabledElement.style.width = width;
		this.width = width;
	};
	this.setHeight = function (height) {
		this.content.style.height = height;
		this.element.style.height = height;
		this.enabledElement.style.height = height;
		this.disabledElement.style.height = height;
		this.height = height;
	};
	this.element = document.createElement("div");
	this.content = this.enabledElement;
	this.element.style.position = "absolute";
	this.element.id = elementId;
	this.enabledElement.onmousedown = function (e) {
		stopEvent(e);
		return true;
	};
	this.enabledElement.onchange = actionListener;
	this.enabledElement.onkeydown = function (e) {
		stopEvent(e);
		return true;
	};
	this.enabledElement.onkeyup = function (e) {
		stopEvent(e);
		return true;
	};
	this.enabledElement.onkeypress = actionListener;
	this.enabledElement.onblur = actionListener;
	this.enabledElement.id = elementId + "_enabled";
	this.enabledElement.type = this.inputType;
	this.disabledElement = document.createElement("span");
	this.disabledElement.id = elementId + "_disabled";
	this.disabledElement.style.visibility = "hidden";
	this.disabledElement.style.display = "none";
	this.disabledElement.style.cursor = "default";
	disableSelect(this.disabledElement);
	this.text = document.createTextNode("");
	this.disabledElement.appendChild(this.text);
	this.disabledElement.onmousedown = actionListener;
	this.disabledElement.ondblclick = actionListener;
	this.element.appendChild(this.enabledElement);
	this.element.appendChild(this.disabledElement);
	this.id = elementId;
	this.value = null;
	this.setValue = setValue;
	this.appendValue = appendValue;
	this.disabled = false;
	this.enable = enable;
	this.disable = disable;
	this.name = name;
	allElements[elementId] = this;
	allElements[elementId + "_disabled"] = this;
	allElements[elementId + "_enabled"] = this;
}
Input.prototype = new Element;
function FileUpload(id) {
	this.actions = new Object();
	this.type = "fileUpload";
	this.id = id;
	this.elements = new Object();
	this.element = document.createElement("div");
	this.element.style.position = "absolute";
	this.element.id = id;
	this.content = this.element;
	allElements[id] = this;
	this.uploadComplete = function () {
		postXML("<state type='uploadComplete'/>");
	};
}
FileUpload.prototype = new Container;
function StatusBar(elementId) {
	this.type = "statusBar";
	this.actions = new Object();
	this.intervalId = null;
	function poll() {
		doGet("FILE_UPLOAD_STATUS");
	}
	this.start = function () {
		this.intervalId = setInterval(poll, 1000);
	};
	this.stop = function () {
		clearInterval(this.intervalId);
	};
	function setValue(value) {
		this.value = value;
		this.progress.style.width = value + "%";
	}
	this.element = document.createElement("div");
	this.element.style.position = "absolute";
	this.content = document.createElement("div");
	this.progress = document.createElement("div");
	this.progress.className = "statusBarProgress";
	this.progress.style.height = "100%";
	this.content.className = "statusBarUnfinished";
	this.content.appendChild(this.progress);
	this.content.style.position = "absolute";
	this.content.value = "0";
	this.content.disabled = null;
	this.content.id = elementId;
	this.element.appendChild(this.content);
	this.id = elementId;
	this.value = "0";
	this.setValue = setValue;
	this.setValue(0);
	allElements[elementId] = this;
}
StatusBar.prototype = new Element;
function Button(elementId, text, action) {
	this.type = "button";
	this.actions = new Object();
	this.id = elementId;
	this.text = text;
	this.action = action;
	this.element = document.createElement("div");
	this.content = document.createElement("button");
	this.element.style.position = "absolute";
	this.content.appendChild(document.createTextNode(text));
	this.element.id = elementId;
	this.element.onmousedown = actionListener;
	this.element.appendChild(this.content);
	allElements[this.id] = this;
}
Button.prototype = new Element;
function Label(id, text) {
	this.actions = new Object();
	this.type = "label";
	this.id = id;
	this.text = text;
	this.element = document.createElement("div");
	this.content = document.createTextNode(text);
	this.element.id = id;
	this.element.onmousedown = actionListener;
	this.element.ondblclick = actionListener;
	this.element.style.position = "absolute";
	this.element.style.cursor = "default";
	this.element.appendChild(this.content);
	disableSelect(this.element);
	allElements[this.id] = this;
	this.setText = function (text) {
		this.text = text;
		var newContent = document.createTextNode(text);
		this.element.replaceChild(newContent, this.content);
		this.content = newContent;
	};
	this.setFontSize = function (size, unit) {
		if (unit) {
			this.element.style.fontSize = size + unit;
		} else {
			this.element.style.fontSize = size + "pt";
		}
	};
	this.setWidth = function (width) {
		this.element.style.width = width;
		this.width = width;
	};
	this.setHeight = function (height) {
		this.element.style.height = height;
		this.height = height;
	};
}
Label.prototype = new Element;
function TableCell(id) {
	this.actions = new Object();
	this.type = "tableCell";
	this.id = id;
	this.element = document.createElement("div");
	this.element.style.position = "absolute";
	this.elements = new Object();
	this.content = this.element;
	allElements[this.id] = this;
	this.addElement = function (eObject) {
		this.elements[eObject.id] = eObject;
		eObject.parent = this;
		eObject.element.style.left = eObject.x;
		eObject.element.style.top = eObject.y;
		this.content.appendChild(eObject.element);
		if (eObject.minimizedIcon) {
			this.addElement(eObject.minimizedIcon);
		}
		if (eObject.width > this.width) {
			this.setWidth(eObject.width);
		}
		if (eObject.height > this.height) {
			this.setHeight(eObject.height);
		}
	};
}
TableCell.prototype = new Container;
function TableRow(id) {
	this.cellX = 0;
	this.actions = new Object();
	this.type = "tableRow";
	this.id = id;
	this.element = document.createElement("div");
	this.element.style.position = "absolute";
	this.content = this.element;
	this.elements = new Object();
	this.addElement = function (cell) {
		cell.setY(0);
		cell.setX(this.width);
		this.setWidth(this.width + cell.width);
		if (cell.height > this.height) {
			this.setHeight(cell.height);
		}
		this.elements[cell.id] = cell;
		this.element.appendChild(cell.element);
	};
	allElements[this.id] = this;
}
TableRow.prototype = new Container;
function Table(id) {
	this.actions = new Object();
	this.type = "table";
	this.id = id;
	this.element = document.createElement("div");
	this.element.style.position = "absolute";
	this.element.cellSpacing = 0;
	this.content = this.element;
	this.elements = new Object();
	this.addElement = function (row) {
		row.setY(this.height);
		row.setX(0);
		this.setHeight(this.height + row.height);
		if (row.width > this.width) {
			this.setWidth(row.width);
		}
		this.elements[row.id] = row;
		this.element.appendChild(row.element);
	};
	allElements[this.id] = this;
}
Table.prototype = new Container;
function Textarea(elementId, value) {
	this.type = "textarea";
	this.actions = new Object();
	function setValue(value) {
		this.value = value;
		this.element.value = value;
		this.element.scrollTop = this.element.scrollHeight;
	}
	function appendValue(value) {
		this.value = this.value + value;
		this.element.value = this.value;
		this.element.scrollTop = this.element.scrollHeight;
	}
	function disable() {
		this.disabled = true;
		this.element.disabled = true;
	}
	function enable() {
		this.disabled = false;
		this.element.disabled = null;
	}
	this.element = document.createElement("div");
	this.content = document.createElement("textarea");
	this.element.style.position = "absolute";
	this.content.value = value;
	this.content.disabled = null;
	this.content.id = elementId;
	this.content.onchange = actionListener;
	this.content.onmousedown = actionListener;
	this.element.appendChild(this.content);
	this.windowId;
	this.id = elementId;
	this.value = value;
	this.setValue = setValue;
	this.appendValue = appendValue;
	this.disabled = false;
	this.enable = enable;
	this.disable = disable;
	allElements[elementId] = this;
}
Textarea.prototype = new Element;
function Layer(id) {
	this.actions = new Object();
	this.type = "layer";
	this.element = document.createElement("div");
	this.element.id = id;
	this.element.style.position = "absolute";
	this.content = this.element;
	this.id = id;
	this.elements = new Object();
	allElements[id] = this;
}
Layer.prototype = new Container;
function closeThisWindow() {
	windowId = getWindowId(this);
	closeWindow(windowId);
	postUpdate(windowId);
}
function maximizeThisWindow() {
	windowId = getWindowId(this);
	maximizeWindow(windowId);
	postUpdate(windowId);
}
function normalThisWindow() {
	windowId = getWindowId(this);
	normalWindow(windowId);
	postUpdate(windowId);
}

